import 'package:flutter/material.dart';

class DrawerDemo extends StatelessWidget {
  // 绑定Scaffold的ScaffoldState，可全局使用
  // 也可通过Builder来获取Scaffold的State
  final _scaffoldkey = new GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldkey,
      appBar: AppBar(
        title: Text('抽屉组件示例'),
      ),
      // 抽屉菜单
      drawer: MediaQuery.removePadding(
        context: context,
        // 移除抽屉菜单顶部默认留白
        removeTop: true,
        child: Drawer(
          child: ListView(
            children: <Widget>[
              Container(
                // Material设计规范中状态栏、导航栏、ListTile高度分别为24、56、56 
                padding: EdgeInsets.only(top: 24),
                color: Theme.of(context).accentColor,
                // 设置用户信息头像、用户名、 Email等
                child: UserAccountsDrawerHeader(
                  margin: EdgeInsets.only(bottom: 8),
                  accountName: Text('玄微子'),
                  accountEmail: Text('416143467@qq.com'),
                  // 设置当前用户头像
                  currentAccountPicture: CircleAvatar(
                    backgroundImage: AssetImage('images/card03.png'),
                  ),
                  onDetailsPressed: () {
                    // 关闭抽屉菜单
                    if (_scaffoldkey.currentState.isDrawerOpen) {
                      Navigator.pop(context, true);
                    }
                  },
                  // 属性本来是用来设置当前用户的其他账号的头像
                  otherAccountsPictures: <Widget>[
                    Container(
                      child: Image.asset('images/card01.png'),
                    )
                  ],
                ),
              ),
              ListTile(
                leading: CircleAvatar(child: Icon(Icons.color_lens)),
                title: Text('个性装扮'),
              ),
              ListTile(
                leading: CircleAvatar(child: Icon(Icons.photo)),
                title: Text('我的相册'),
              ),
              ListTile(
                leading: CircleAvatar(child: Icon(Icons.wifi)),
                title: Text('免流量特权'),
              ),
            ],
          ),
        ),
      ),
      // 底部导航内嵌悬浮按钮
      bottomNavigationBar: BottomAppBar(
        // 底部工具栏的颜色
        color: Colors.white,
        // 底部导航栏打一个圆形的洞
        shape: CircularNotchedRectangle(),
        child: Row(
          // 均分底部导航栏横向空间
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.home),
              onPressed: () {},
            ),
            SizedBox(),
            IconButton(
              icon: Icon(Icons.business),
              onPressed: () {},
            ),
          ],
        ),
      ),
      // 悬浮按钮
      floatingActionButton:
          FloatingActionButton(
            child: Icon(Icons.add), 
            onPressed: () {}
          ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      body: Center(child: Text('抽屉')),
    );
  }
}
